package first.progr.tc;

import static first.progr.helpstaff.ContactHelper.MODIFICATION;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Random;

import org.testng.annotations.Test;

import first.progr.utils.SortedListOf;
public class ContactModificationTest extends TestBase {

	@Test(dataProvider = "randomValidContactGenerator")
	public void modifySomeContact(ContactData cont1) throws Exception {
	  // Save old contacts state 
	  SortedListOf<ContactData> oldContactsList = app.getContactHelper().getContacts();
	  
	  Random rnd = new Random();
	  int index = rnd.nextInt(oldContactsList.size()-1);
	  
	  // Actions
	  app.getContactHelper().modifyContact(cont1, index, MODIFICATION);
	  
	  //Save new contacts state
	  SortedListOf<ContactData> newContactsList = app.getContactHelper().getContacts();
		
	  // Compare states of lists
	  assertThat(newContactsList, equalTo(oldContactsList.without(index).withAdded(cont1)));
	}
	
}
